/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package reamodel.impl;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EcoreUtil;

import reamodel.DecrementEconomicEventType;
import reamodel.EconomicResourceType;
import reamodel.OutflowType;
import reamodel.ReamodelPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Outflow Type</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link reamodel.impl.OutflowTypeImpl#getResourceType <em>Resource Type</em>}</li>
 *   <li>{@link reamodel.impl.OutflowTypeImpl#getEventType <em>Event Type</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class OutflowTypeImpl extends StockflowTypeImpl implements OutflowType {
	/**
	 * The cached value of the '{@link #getResourceType() <em>Resource Type</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getResourceType()
	 * @generated
	 * @ordered
	 */
	protected EconomicResourceType resourceType;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected OutflowTypeImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return ReamodelPackage.Literals.OUTFLOW_TYPE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EconomicResourceType getResourceType() {
		if (resourceType != null && resourceType.eIsProxy()) {
			InternalEObject oldResourceType = (InternalEObject)resourceType;
			resourceType = (EconomicResourceType)eResolveProxy(oldResourceType);
			if (resourceType != oldResourceType) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, ReamodelPackage.OUTFLOW_TYPE__RESOURCE_TYPE, oldResourceType, resourceType));
			}
		}
		return resourceType;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EconomicResourceType basicGetResourceType() {
		return resourceType;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetResourceType(EconomicResourceType newResourceType, NotificationChain msgs) {
		EconomicResourceType oldResourceType = resourceType;
		resourceType = newResourceType;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ReamodelPackage.OUTFLOW_TYPE__RESOURCE_TYPE, oldResourceType, newResourceType);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setResourceType(EconomicResourceType newResourceType) {
		if (newResourceType != resourceType) {
			NotificationChain msgs = null;
			if (resourceType != null)
				msgs = ((InternalEObject)resourceType).eInverseRemove(this, ReamodelPackage.ECONOMIC_RESOURCE_TYPE__OUTFLOW_TYPE, EconomicResourceType.class, msgs);
			if (newResourceType != null)
				msgs = ((InternalEObject)newResourceType).eInverseAdd(this, ReamodelPackage.ECONOMIC_RESOURCE_TYPE__OUTFLOW_TYPE, EconomicResourceType.class, msgs);
			msgs = basicSetResourceType(newResourceType, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ReamodelPackage.OUTFLOW_TYPE__RESOURCE_TYPE, newResourceType, newResourceType));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DecrementEconomicEventType getEventType() {
		if (eContainerFeatureID != ReamodelPackage.OUTFLOW_TYPE__EVENT_TYPE) return null;
		return (DecrementEconomicEventType)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetEventType(DecrementEconomicEventType newEventType, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newEventType, ReamodelPackage.OUTFLOW_TYPE__EVENT_TYPE, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setEventType(DecrementEconomicEventType newEventType) {
		if (newEventType != eInternalContainer() || (eContainerFeatureID != ReamodelPackage.OUTFLOW_TYPE__EVENT_TYPE && newEventType != null)) {
			if (EcoreUtil.isAncestor(this, newEventType))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newEventType != null)
				msgs = ((InternalEObject)newEventType).eInverseAdd(this, ReamodelPackage.DECREMENT_ECONOMIC_EVENT_TYPE__OUTFLOW_TYPE, DecrementEconomicEventType.class, msgs);
			msgs = basicSetEventType(newEventType, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ReamodelPackage.OUTFLOW_TYPE__EVENT_TYPE, newEventType, newEventType));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ReamodelPackage.OUTFLOW_TYPE__RESOURCE_TYPE:
				if (resourceType != null)
					msgs = ((InternalEObject)resourceType).eInverseRemove(this, ReamodelPackage.ECONOMIC_RESOURCE_TYPE__OUTFLOW_TYPE, EconomicResourceType.class, msgs);
				return basicSetResourceType((EconomicResourceType)otherEnd, msgs);
			case ReamodelPackage.OUTFLOW_TYPE__EVENT_TYPE:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetEventType((DecrementEconomicEventType)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ReamodelPackage.OUTFLOW_TYPE__RESOURCE_TYPE:
				return basicSetResourceType(null, msgs);
			case ReamodelPackage.OUTFLOW_TYPE__EVENT_TYPE:
				return basicSetEventType(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID) {
			case ReamodelPackage.OUTFLOW_TYPE__EVENT_TYPE:
				return eInternalContainer().eInverseRemove(this, ReamodelPackage.DECREMENT_ECONOMIC_EVENT_TYPE__OUTFLOW_TYPE, DecrementEconomicEventType.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case ReamodelPackage.OUTFLOW_TYPE__RESOURCE_TYPE:
				if (resolve) return getResourceType();
				return basicGetResourceType();
			case ReamodelPackage.OUTFLOW_TYPE__EVENT_TYPE:
				return getEventType();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case ReamodelPackage.OUTFLOW_TYPE__RESOURCE_TYPE:
				setResourceType((EconomicResourceType)newValue);
				return;
			case ReamodelPackage.OUTFLOW_TYPE__EVENT_TYPE:
				setEventType((DecrementEconomicEventType)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case ReamodelPackage.OUTFLOW_TYPE__RESOURCE_TYPE:
				setResourceType((EconomicResourceType)null);
				return;
			case ReamodelPackage.OUTFLOW_TYPE__EVENT_TYPE:
				setEventType((DecrementEconomicEventType)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case ReamodelPackage.OUTFLOW_TYPE__RESOURCE_TYPE:
				return resourceType != null;
			case ReamodelPackage.OUTFLOW_TYPE__EVENT_TYPE:
				return getEventType() != null;
		}
		return super.eIsSet(featureID);
	}

} //OutflowTypeImpl
